//
//  ZH_GoodsInformationTableViewCell.m
//  ChangeMerchants
//
//  Created by zhangliwen on 2018/9/28.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_GoodsInformationTableViewCell.h"
#import <WebKit/WebKit.h>
@interface ZH_GoodsInformationTableViewCell()
@property (nonatomic,weak)UILabel *titleLabel;
@property (nonatomic,weak)UIImageView *leftImage;
@property (nonatomic,weak)UIImageView *rightImage;
@property (weak, nonatomic)WKWebView *webView;
@end
@implementation ZH_GoodsInformationTableViewCell

///创建
+ (instancetype)cellWithTableView:(UITableView*)tableView
{
    static NSString *ID = @"ZH_GoodsInformationTableViewCell";
    ZH_GoodsInformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell == nil){
        cell = [[ZH_GoodsInformationTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}
///初始化
-(void)initDefault
{
    [self unShowClickEffect];
    
}
- (void)loadSubviewConstraints{
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(FITSCALE(16));
        make.centerX.equalTo(self.contentView);
    }];
    [self.leftImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.titleLabel);
        make.right.equalTo(self.titleLabel.mas_left).offset(FITSCALE(-18));
    }];
    [self.rightImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.titleLabel);
        make.left.equalTo(self.titleLabel.mas_right).offset(FITSCALE(18));
    }];
    [self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom);
        make.left.right.equalTo(self.contentView);
        make.height.mas_equalTo(kMainScreenHeight);
        make.bottom.equalTo(self.contentView);
    }];
}
- (void)setTitleString:(NSString *)titleString{
    self.titleLabel.text = titleString;
}
- (void)updata:(NSDictionary *)dic{
    if (dic) {
        NSString *htmlString = [NSString stringWithFormat:@"%@%@%@",@"<html><head><meta name='viewport' content='width=device-width,initial-scale=1,maximum-scale=1.0,user-scalable=no'><meta name='format-detection' content='telephone=yes'/> <style>body {padding-left:10px;padding-right:10px;padding-bottom: 20%; } img{ max-width:100%;height:auto; }</style></head><body>",dic[@"goods"][@"detail"],@"</body></html>"];
        [self.webView loadHTMLString:htmlString baseURL:nil];
        //         [self.webView loadHTMLString: baseURL:nil];
    }
}
#pragma mark - getter,setter
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        UILabel *label = [UILabel createLabelWithText:@"商品详情" font:kFontSize_30];
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont boldSystemFontOfSize:15];
        [self.contentView addSubview:_titleLabel = label];
    }
    return _titleLabel;
}
- (UIImageView *)leftImage{
    if (!_leftImage) {
        UIImageView *image = [UIImageView createImageViewWithName:@"img_tip_left"];
        [self.contentView addSubview:_leftImage = image];
    }
    return _leftImage;
}
- (UIImageView *)rightImage{
    if (!_rightImage) {
        UIImageView *image = [UIImageView createImageViewWithName:@"img_tip_right"];
        [self.contentView addSubview:_rightImage = image];
    }
    return _rightImage;
}
- (WKWebView *)webView
{
    if(!_webView){
        WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, kMainScreenWidth, kMainScreenHeight)];
        webView.scrollView.showsVerticalScrollIndicator = YES;
        webView.scrollView.showsHorizontalScrollIndicator = NO;
        webView.scrollView.contentInset = UIEdgeInsetsMake(FITHEIGHT(0), 0, 0, 0);
        webView.scrollView.bounces = NO;
        [self.contentView addSubview:_webView = webView];
    }
    return _webView;
}
@end
